package com.zhima.controller.plain;

import com.zhima.dto.ContestQuestionDTO;
import com.zhima.dto.ZhimaOjResult;
import com.zhima.entity.OjQuestionBindContest;
import com.zhima.service.OjQuestionBindContestService;
import com.zhima.util.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.zhima.dto.ZhimaOjResult.success;

@RestController
@RequestMapping("/question-bind-contest")
public class OjQuestionBindContestController {
    @Autowired
    private OjQuestionBindContestService ojQuestionBindContestService;

    @PostMapping("/bind")
    public ZhimaOjResult bindQuestionToContest(@RequestBody OjQuestionBindContest ojQuestionBindContest) {
        return success(ojQuestionBindContestService.bindQuestionToContest(UserHolder.get().getId(), ojQuestionBindContest));
    }

    @PostMapping("/unbind/{contestId}/{questionIndex}")
    public ZhimaOjResult unbindQuestionToContest(@PathVariable("contestId") Long contestId, @PathVariable("questionIndex") Integer questionIndex) {
        return success(ojQuestionBindContestService.unbindQuestionToContest(UserHolder.get().getId(), contestId, questionIndex));
    }

    @PostMapping("/change/{contestId}")
    public ZhimaOjResult changeQuestionIndex(@RequestBody ContestQuestionDTO[] afterSequence, @PathVariable("contestId") Long contestId) {
        return success(ojQuestionBindContestService.changeQuestionIndex(UserHolder.get().getId(),contestId, afterSequence));
    }
}
